// JavaScript Document
window.onload=function(){
	var main_li=document.getElementsByClassName('banner_main_li');
	var item_li=document.getElementsByClassName('banner_item_li');
	var left=document.getElementsByClassName('left');
	var right=document.getElementsByClassName('right');
	var n=0,y=1;
	function run(){
		// n自增代表图片的切换
    	n++;
    	if(n==6){
           n=0;
    	}
    	// 全部打死，将之前的样式清空
    	for (var i = 0; i < main_li.length; i++) {
    		main_li[i].style.display = "none";
    		item_li[i].style.background = "#3E3E3E";
    	};
    	main_li[n].style.display = "block";
    	item_li[n].style.background = "#B61B1F";
    	// 点击左侧按钮切换图片
    	left[0].onclick=function(){
			clearInterval(timer);
			y=-1;
			
			// 清空所有样式
			for (var i = 0; i < main_li.length; i++) {
	    		main_li[i].style.display = "none";
	    		item_li[i].style.background = "#3E3E3E";
    		};
			n=n+y;
			main_li[n].style.display = "block";
    		item_li[n].style.background = "#B61B1F";
			if(n==0){
				n=6;
			};	
		}
		left[0].onmouseover=function(){
			clearInterval(timer);			
		}
		left[0].onmouseout=function(){
			timer=setInterval(run,2000);
		}
		right[0].onclick=function(){
			clearInterval(timer);
			y=1;
			
			// 清空所有样式
			for (var i = 0; i < main_li.length; i++) {
	    		main_li[i].style.display = "none";
	    		item_li[i].style.background = "#3E3E3E";
    		};
			n=n+y;
			main_li[n].style.display = "block";
    		item_li[n].style.background = "#B61B1F";
			if(n==5){
				n=-1;
			};	
		}
		right[0].onmouseover=function(){
			clearInterval(timer);			
		}
		right[0].onmouseout=function(){
			timer=setInterval(run,2000);
		}
    }
    timer = setInterval(run,2000);
    for (var j = 0; j < item_li.length; j++) {
    	item_li[j].xuhao = j;
    	// 鼠标移入停止定时器
    	item_li[j].onmouseover=function(){
    		clearInterval(timer);
	    	// 全部打死
	    	for (var i = 0; i < main_li.length; i++) {
	    		main_li[i].style.display = "none";
	    		item_li[i].style.background = "#3E3E3E";
	    	};    
	    	// 救活一个	（n保持一致）	
	    	n = this.xuhao;
	    	main_li[n].style.display = "block";
    		item_li[n].style.background = "#B61B1F";
    	}
    	// 鼠标移出开启定时器
    	item_li[j].onmouseout=function(){
    		timer = setInterval(run,2000);
    	}
    };
}